﻿package mortal.game.view.copy.ChallengeCopy.newView
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.utils.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;

    public class ChallengeMopRender extends GCellRenderer
    {
        private var _sectionInfoTxt:GTextFiled;
        private var _bossName:GTextFiled;
        private var _exp:GTextFiled;
        private var _rewardList:Vector.<BaseItem>;
        private var _info:SChallengeMopReward;
        private var _tchallenge:TChallengeCopy;

        public function ChallengeMopRender()
        {
            this._rewardList = new Vector.<BaseItem>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTxtBg, 0, 0, this));
            this.pushUIToDisposeVec(UIFactory.bg(0, 124, 330, 2, this, ImagesConst.SplitLine));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35117), 0, 45, 100, 20, this, null, true));
            this._sectionInfoTxt = UIFactory.gTextField("", 0, 2, 220, 22, this);
            this._bossName = UIFactory.gTextField("", 0, 28, 220, 20, this);
            this._exp = UIFactory.gTextField("", 58, 100, 220, 20, this);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._sectionInfoTxt.dispose(param1);
            this._sectionInfoTxt = null;
            this._bossName.dispose(param1);
            this._bossName = null;
            this._exp.dispose(param1);
            this._exp = null;
            this._info = null;
            this._tchallenge = null;
            this.removeRewardItems();
            super.disposeImpl(param1);
            return;
        }// end function

        private function removeRewardItems() : void
        {
            var _loc_1:BaseItem = null;
            for each (_loc_1 in this._rewardList)
            {
                
                _loc_1.dispose(true);
            }
            this._rewardList.length = 0;
            return;
        }// end function

        private function combineItem() : Dictionary
        {
            var _loc_2:SReward = null;
            var _loc_3:int = 0;
            var _loc_1:* = new Dictionary();
            while (_loc_3 < this._info.rewards.length)
            {
                
                _loc_2 = this._info.rewards[_loc_3];
                if (_loc_1[_loc_2.code])
                {
                    _loc_1[_loc_2.code] = _loc_1[_loc_2.code] + _loc_2.num;
                }
                else
                {
                    _loc_1[_loc_2.code] = _loc_2.num;
                }
                _loc_3++;
            }
            return _loc_1;
        }// end function

        private function updateRewardList() : void
        {
            var _loc_1:BaseItem = null;
            var _loc_2:Dictionary = null;
            var _loc_3:String = null;
            var _loc_4:int = 0;
            this.removeRewardItems();
            _loc_2 = this.combineItem();
            for (_loc_3 in _loc_2)
            {
                
                _loc_1 = UICompomentPool.getUICompoment(BaseItem);
                _loc_1.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
                var _loc_7:Boolean = false;
                _loc_1.isDropAble = false;
                _loc_1.isDragAble = _loc_7;
                _loc_1.isShowLock = true;
                _loc_1.itemData = new ItemData(int(_loc_3));
                _loc_1.amount = _loc_2[_loc_3];
                this.addChild(_loc_1);
                this._rewardList.push(_loc_1);
            }
            _loc_4 = 0;
            while (_loc_4 < this._rewardList.length)
            {
                
                this._rewardList[_loc_4].x = _loc_4 * 45 + 62;
                this._rewardList[_loc_4].y = 50;
                _loc_4++;
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._info = param1["info"];
            this._tchallenge = param1["tchallenge"];
            if (this._tchallenge)
            {
                this._sectionInfoTxt.htmlText = "<font color=\'#fd992f\'>" + this._tchallenge.towerName + "</font>-<font color=\'#1bbee1\'>" + this._tchallenge.sectionName + "</font>-<font color=\'#1ccc31\'>" + this._tchallenge.levelName + "</font>";
                this._bossName.htmlText = Language.getString(35118) + BossConfig.instance.getInfoByCode(int(this._tchallenge.bossId)).name + "</font>";
            }
            this.updateRewardList();
            this._exp.htmlText = Language.getString(35119) + this._info.exp;
            this._exp.y = this._rewardList.length > 0 ? (98) : (45);
            return;
        }// end function

    }
}
